package com.neusoft.newelm.converter;

import java.util.ArrayList;
import java.util.List;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import com.neusoft.newelm.bean.Role;
import com.neusoft.newelm.common.ElmException;

/**
 * 
 * @author chens
 *
 */
@Component("RoleListConverter")
public class RoleListConverter implements Converter<String[], List<Role>> {

	@Override
	public List<Role> convert(String[] source) {

		if (source != null && source.length > 0) {
			List<Role> list = new ArrayList<Role>();
			for (String roleId : source) {
				try {
					list.add(new Role(Integer.valueOf(roleId), null));
				} catch (RuntimeException e) {
					throw new ElmException("角色ID转换异常");
				}
			}
			return list;
		}
		return null;
	}

}
